<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form name="form">
        <input type="text" name="username" id="username">
    </form>

    <script>

        document.form.username.onfocus = function () {
            console.log('onfocus');
        }
        document.form.username.onblur = function () {
            console.log('onblur');
        }

        document.form.username.focus();
        setTimeout(() => {
            document.form.username.blur();
        }, 3000);


    </script>
</body>

</html>